import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[n];
        for(int i = 0; i < n; i++){
            if(i == 0) b[i] = sc.nextInt();
            else b[i] = b[i-1] + sc.nextInt();
        }
        int count = 0, l = 0, r = n/2;
        while(l < r){
            int mid = (r + l + 1) / 2;
            if(check(mid, b, n)){
                count = Math.max(count, mid);
                l = mid;
            }
            else r = mid - 1;

        }
        //ok
        System.out.println(count * 2);
    }
    public static boolean check(int mid, int[] b, int n){
        int l = 0, count = 0;
        if(b[mid*2] == mid)  return true;
        for(int i = mid * 2; i < n; i++){
            if((b[i] - b[i - mid * 2]) * 2 == i - (i - mid * 2)) {
                //count = i-l;
                return true;
            }
            l++;
        }
        return false;
    }
}